<script type="text/javascript">
var swfu_
$(function(){
	var btn = $("#upbtn").get(0);
    swfu_= new SWFUpload({
    			upload_url: "/upload/upload",
                file_post_name: "filedata",
				file_size_limit : "1 MB",
				file_types : "*.jpg;*.png;*.jpeg'*.bmp",
				file_types_description : "bmp,jpeg,jpg,png图片",
				file_upload_limit :5,
				post_params : {
		           "bizType" : "SHOP",
		           "fileType" : "IMAGE",
		           "fileName" : ""
			    },
				swfupload_preload_handler : preLoad,
				swfupload_load_failed_handler : loadFailed,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : function(f,data){
					eval("var json="+data+";");
					if(json.message=="Success!"){
						var htmstr="";
						htmstr+="<div style='float:left;'>";
						htmstr+='<input type="hidden" name="shop.logo" value="'+json.data.urls+'">';
						htmstr+='<img height="200px"src="'+json.data.urls+'"/>';
						htmstr+='<br/><a href="#" class="easyui-linkbutton" onclick="javascript:$(this).parent().remove();"><b>删除</b></a>';
						htmstr+='</div>';
						$("#img_div").append(htmstr);
						/*$('.easyui-linkbutton').linkbutton({    
						    iconCls: 'icon-remove'
						}); */ 
					}else{
						$.messager.alert('警告','文件上传出错');
					}
				},
				upload_complete_handler : uploadComplete,
				// Button Settings
				button_placeholder_id:"upbtn",
				button_image_url : "/img/SmallSpyGlassWithTransperancy_17x18.png",
				button_width: 80,
				button_height: 18,
				button_text : '<span class="button">上传商铺图片</span>',
				button_text_style : '.button {font-size: 12pt; }',
				button_text_top_padding: 0,
				button_text_left_padding: 18,
				button_disabled : false,
				button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				button_cursor: SWFUpload.CURSOR.HAND,
				// Flash Settings
				flash_url : swfuploaddir+"/swfupload.swf",
				flash9_url : swfuploaddir+"/swfupload_fp9.swf",
				custom_settings : {
				//	upload_target : "divFileProgressContainer",
					thumbnail_height: 500,
					thumbnail_width: 500,
					thumbnail_quality: 100
				},
				debug: true
			});
   
    
var curMarketId = $("#marketId").val();     
if(curMarketId!=''){
    var shopCategoryIdStr = $("#shopCategoryIdStr").val();
    var sgCatIdArray = shopCategoryIdStr.split(",");
	$.ajax({
		url: '/shopCategory/findMarketCategory/' + curMarketId,
			dataType: "json",
			success : function(data) {
			if (data.success) {
				var htmlStr = "";
				$.each(data.obj, function (i, item) {  
					htmlStr += "<input type='checkbox' name='shopCategories' value='"+item.id+"'";
					
					if(sgCatIdArray.length > 0){
						$.each(sgCatIdArray, function(n, value){
							if(value==item.id){
								htmlStr += " checked=checked ";   
							}
						})
					}
					
					htmlStr += "/>"+item.name+" &nbsp;";
					if((i+1)%3==0){
						htmlStr += "<br>";
					}
				});
				$("#categoryHtml").html(htmlStr);
			} else {
				$("#categoryHtml").html("该市场下无商铺类型，请先添加！");
				//$.messager.alert("操作失败",data.msg,'error');
			}
		}
	}); 
}

	
		    $('#marketId').combobox({    
		    	url: '/market/combobox',   
    		    valueField:'id',    
    		    textField:'name',
    		    required: true,
    		    width:122,
    		    onSelect:function(record){  
    		    	/* $("#categoryId").combobox({
    		    		url: '/shopCategory/comboboxMarketCategory/' + record.id,    
    		    		valueField:'id',    
    				    textField:'name',
		    		    required: true
		    		}) */
    		    	$.ajax({
    					url: '/shopCategory/findMarketCategory/' + record.id,
    		   			dataType: "json",
    		   			success : function(data) {
    		   				if (data.success) {
    							/* $.messager.show({
    								msg:data.msg,
    								title:'提示'
    							}); */
    							var htmlStr = "";
    							$.each(data.obj, function (i, item) {  
    								htmlStr += "<input type='checkbox' name='shopCategories' value='"+item.id+"'/>"+item.name+" &nbsp;";
    								if((i+1)%3==0){
    									htmlStr += "<br>";
    								}
    							});
    							$("#categoryHtml").html(htmlStr);
    						} else {
    							$("#categoryHtml").html("该市场下无商铺类型，请先添加！");
    							//$.messager.alert("操作失败",data.msg,'error');
    						}
    					}
    				}); 
		    	}
		    });
		    
		    $("#userId").combobox({    
			    url: '/merchant/combobox',   
			    valueField:'id',    
			    textField:'name',
			    required: true,
			    width:122
			}); 
		    
		});
		
</script>

<form method="post" id="editForm" name="editForm">
	<input type="hidden" name="shop.id" value="${(po.id)!}" id="poid">
	<div id="tt" class="easyui-tabs" style="width: 786px; height: 450px;">
		<div title="商铺信息" style="padding: 5px;">
			<table class="tableForm tableCss">
				<tr>
					<th><font color=red>*</font>所属市场</th>
					<td colspan="3"><input id="marketId" name="shop.market_id" value="${(po.market_id)!}"></td>
				</tr>
				<tr>
					<th><font color=red>*</font>所属类别</th>
					<td colspan="3">
						<!-- <input id="categoryId" name="shop.category_id" value="${(po.category_id)!}"> -->
						<div id="categoryHtml">请先选择市场</div>
						<input type="hidden" name="shopCategoryIdStr" value="${(shopCategoryIdStr)!}" id="shopCategoryIdStr">
					</td>
				</tr>
				<tr>
					<th><font color=red>*</font>选择账户</th>
					<td><input id="userId" name="shop.merchant_id" value="${(po.merchant_id)!}"></td>
					<th>状态</th>
					<td>
						<input name="shop.status" class="easyui-combobox" value="${(po.status)!1}"
						data-options="valueField: 'label',textField: 'value',
						data: [{label: '0',value: '冻结'},{label: '1',value: '正常'}]">
					</td>
				</tr>
				<tr>
					<th>商铺名称</th>
					<td colspan="1"><input type="text" name="shop.name" class="easyui-validatebox" value="${(po.name)!}" data-options="required:true"></td>
					<th>是否推荐</th>
					<td>
						<input name="shop.recommend" class="easyui-combobox" value="${(po.recommend)!0}"
						data-options="valueField: 'label',textField: 'value',
						data: [{label: '0',value: '否'},{label: '1',value: '是'}]">
					</td>
				<tr>
					<th>商铺联系电话</th>
					<td colspan="1">
						<input name="shop.phone" value="${(po.phone)!}"/>
					</td>
					<th>排序（填数值）</th>
					<td colspan="1"><input type="text" name="shop.seq" class="easyui-validatebox" value="${(po.seq)!}" style="width: 40px;" data-options="required:true">&nbsp;数值越大越靠后</td>
				</tr>
				<tr>
					<th>商铺简介</th>
					<td colspan="3">
						<textarea name="shop.summary" cols="70" rows="4">${(po.summary)!}</textarea>
					</td>
				</tr>
				<tr>
					<th>商铺地址</th>
					<td colspan="3">
					<input type="text" name="shop.address" class="easyui-validatebox" value="${(po.address)!}" style="width:200px;">
					</td>
				</tr>
				<tr>
					<th>营业时间</th>
					<td colspan="3"><input type="text" name="shop.work_hours" class="easyui-validatebox" value="${(po.work_hours)!}" style="width:200px;"></td>
				</tr>
			</table>
		</div>
		<div title="图片" style="padding:5px;">
			<div class="tableForm datagrid-toolbar" >
				<div style="width:60px;border:1px;">
					<span id="upbtn"></span>
				</div>
				<div id="img_div">
					<#if po?? && po.logo??>
					<div style='float:left;'>
						<input type="hidden" name="logo" value="${(po.logo)!}">
						<img src="${(po.logo)!}" height="200px"/>
						<br/>
						<a href="#" class="easyui-linkbutton" onclick="javascript:$(this).parent().remove();"><b>删除</b></a>
					</div>
					</#if>
				</div>
			</div>
		</div>
	</div>
</form>
